<?php
class FinanceMonthModel
{
	private $tableName = 'e_finance_month';
	
	public function getById($id)
	{
		$sql = "select * from $this->tableName where FinanceId=$id limit 0,1";
		$result = mysql_query ( $sql );
		return mysql_fetch_object ( $result );
	}
	
	public function getExcelById($id)
	{
		$sql = "select `OperationTime`,`InMoney`,`OutMoney`, `Balance` ,`Description`,`Operater` from $this->tableName where FinanceId=$id limit 0,1";
		$result = mysql_query ( $sql );
		return mysql_fetch_object ( $result );
	}
	//不添加Photo
	public function addInfo($info)
	{
		$info->CreateTime=$info->CreateTime.' '.date('h:i:s');
		$sql = "insert into $this->tableName (InMoney,OutMoney,Operater,OperationTime,Description,MoneyType,Balance,CreateTime)";
		$sql .="values('" . $info->InMoney . "','" .$info->OutMoney. "','" .$info->Operater. "','" .$info->OperationTime. "','" .$info->Description. "','" .$info->MoneyType. "','" .$info->Balance. "','" .$info->CreateTime. "')";
		echo $sql;
		mysql_query ( $sql );
		
		return mysql_insert_id ();
	}
	public function setInfoById($info, $id)
	{
		require_once SOURCE_EXT_PATH . 'common/ModelLib.class.php';
		$model = new E_finance_month();
		$sql = "update $this->tableName set ";
		foreach ( $model as $key => $value )
		{
			if (isset ( $info->$key ))
			{
				$sql .= "`" . $key . "`='" . $info->$key . "',";
			}
		}
		$sql = substr ( $sql, 0, - 1 );
		$sql .= " where `FinanceId` = $id limit 1";
		return mysql_query ( $sql );
	}
	public function getCount($where)
	{
		$sql = "select count(FinanceId) as sum from $this->tableName $where ";
		$result = mysql_query ( $sql );
		return mysql_fetch_object ( $result );
	}
	
	public function getList($where,$start,$len)
	{
		$sql = "select * from $this->tableName $where order by FinanceId asc limit $start,$len";
		$result = mysql_query ( $sql );
		$info = array ();
		while ( $row = mysql_fetch_assoc ( $result ) )
		{
			$info [] = $row;
		}
		return $info;
	}
	public function delById($id){
		$sql="delete from $this->tableName where FinanceId=$id limit 1";
		return mysql_query($sql);
	}
}